home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / all java / quicktime for java / dukemovie / src / dukemovie.java
Encoding:
Java Source  |  2000-06-23  |  2.1 KB  |  88 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.awt.*;
  9. import java.io.IOException;
  10. import java.io.File;
  11. import java.awt.event.*;
  12.  
  13. import quicktime.*;
  14. import quicktime.app.QTFactory;
  15. import quicktime.io.QTFile;
  16. import quicktime.util.*;
  17.  
  18. import duke.*;
  19. /**
  20.  * Moving Movie Demo.
  21.  */
  22. public class DukeMovie extends Frame {
  23. //_________________________ CLASS VARIABLES
  24.     private static final Color bgColor = Color.lightGray; //tumbling duke gif's are light gray
  25.  
  26. //_________________________ CLASS METHODS
  27.     public static void main(String args[]) {
  28.         try {
  29.             QTSession.open(); //start a QuickTime session
  30.             Frame f = new DukeMovie("Biscotti = Java + QuickTime");
  31.             f.show();
  32.             f.toFront();
  33.         }
  34.         catch (Exception e) { 
  35.             QTSession.close(); 
  36.             System.exit(0); 
  37.         }
  38.     }
  39.  
  40.     DukeMovie (String frameTitle) throws QTException, IOException {
  41.         super (frameTitle);
  42.  
  43.         setBackground(bgColor);
  44.         setLayout(new BorderLayout());
  45.  
  46.         ms = new MovieScreen();
  47.         add("Center", ms.getCanvas());
  48.         
  49.         // create, add and start tumbling duke, if the images are available
  50.         try {
  51.             File file = QTFactory.findAbsolutePath ("duke");        
  52.             duke = new TumbleItem(file.getAbsolutePath());
  53.         } catch (Exception e) {
  54.             e.printStackTrace();
  55.         }
  56.         if (duke != null) {
  57.             duke.setBackground(bgColor);
  58.             add("North", duke);
  59.         }
  60.         
  61.         // create our little control panel out of simple AWT objects
  62.         cp = new ControlPanel(bgColor, ms);
  63.         add("South", cp);
  64.  
  65.         setBounds(0, 0, 625, 420);
  66.         addWindowListener(new WindowAdapter () {
  67.             public void windowOpened (WindowEvent ev) {
  68.                 if (duke != null) duke.start();
  69.             }
  70.  
  71.             public void windowClosing (WindowEvent e) {
  72.                 if (duke != null) duke.stop();
  73.                 QTSession.close();
  74.                 dispose();
  75.             }
  76.  
  77.             public void windowClosed (WindowEvent e) { 
  78.                 System.exit(0);
  79.             }
  80.         });
  81.     }
  82.  
  83. //_________________________ INSTANCE VARIABLES
  84.     private MovieScreen ms;
  85.     private TumbleItem  duke;
  86.     private ControlPanel cp;
  87. }
  88.